package com.ruoyi.web.controller.phonecase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.PcFriend;
import com.ruoyi.system.service.IPcFriendService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 好友关系Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/phonecase/friend")
public class PcFriendController extends BaseController
{
    @Autowired
    private IPcFriendService pcFriendService;

    /**
     * 查询好友关系列表
     */
    @PreAuthorize("@ss.hasPermi('phonecase:friend:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcFriend pcFriend)
    {
        startPage();
        List<PcFriend> list = pcFriendService.selectPcFriendList(pcFriend);
        return getDataTable(list);
    }

    /**
     * 导出好友关系列表
     */
    @PreAuthorize("@ss.hasPermi('phonecase:friend:export')")
    @Log(title = "好友关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcFriend pcFriend)
    {
        List<PcFriend> list = pcFriendService.selectPcFriendList(pcFriend);
        ExcelUtil<PcFriend> util = new ExcelUtil<PcFriend>(PcFriend.class);
        util.exportExcel(response, list, "好友关系数据");
    }

    /**
     * 获取好友关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('phonecase:friend:query')")
    @GetMapping(value = "/{friendId}")
    public AjaxResult getInfo(@PathVariable("friendId") Long friendId)
    {
        return success(pcFriendService.selectPcFriendByFriendId(friendId));
    }

    /**
     * 新增好友关系
     */
    @PreAuthorize("@ss.hasPermi('phonecase:friend:add')")
    @Log(title = "好友关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcFriend pcFriend)
    {
        pcFriend.setCreateBy(getUsername());
        return toAjax(pcFriendService.insertPcFriend(pcFriend));
    }

    /**
     * 修改好友关系
     */
    @PreAuthorize("@ss.hasPermi('phonecase:friend:edit')")
    @Log(title = "好友关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcFriend pcFriend)
    {
        pcFriend.setUpdateBy(getUsername());
        return toAjax(pcFriendService.updatePcFriend(pcFriend));
    }

    /**
     * 删除好友关系
     */
    @PreAuthorize("@ss.hasPermi('phonecase:friend:remove')")
    @Log(title = "好友关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{friendIds}")
    public AjaxResult remove(@PathVariable Long[] friendIds)
    {
        return toAjax(pcFriendService.deletePcFriendByFriendIds(friendIds));
    }
}

